{extend name="base" /}
{block name="main"}
<div class="tpl-content-wrapper">
    <div class="tpl-content-page-title">
        商品列表
    </div>
    <ol class="am-breadcrumb">
        <li><a href="#" class="am-icon-home">首页</a></li>
        <li><a href="#">商品管理</a></li>
        <li class="am-active">商品列表</li>
    </ol>
    <div class="tpl-portlet-components">
        <div class="portlet-title">
            <div class="caption font-green bold">
                <span class="am-icon-code"></span> 列表
            </div>
            <div class="tpl-portlet-input tpl-fz-ml">
                <div class="portlet-input input-small input-inline">
                    <div class="input-icon right">
                        <i class="am-icon-search"></i>
                        <input type="text" class="form-control form-control-solid" id="findcode" placeholder="搜索股票代码"> </div>
                </div>
            </div>


        </div>
        <div class="tpl-block">
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a href="{:url('goods/Goods/create')}" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</a>



                        </div>
                    </div>
                </div>


            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main am-table-centered">
                            <thead>
                            <tr>
                                <th class="table-check"><input type="checkbox" class="tpl-table-fz-check"></th>
                                <th class="table-id">ID</th>
                                <th class="table-title">股票代码</th>
                                <th class="table-type">商品名</th>
                                <th class="table-date am-hide-sm-only">HOT</th>
                                <th class="table-date am-hide-sm-only">状态</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name='data' id='goods'}
                            <tr>
                                <td><input type="checkbox"></td>
                                <td>{$goods.id}</td>
                                <td>{$goods.stockcode}</td>
                                <td>{$goods.name}</a></td>
                                {if $goods.hot==1}
                                <td class="am-hide-sm-only"><a class="u-hot" u-hot="{$goods.hot}" u-uid="{$goods.id}">HOT</a></td>
                                {else}
                                <td class="am-hide-sm-only"><a style="color: #93a2a9" class="u-hot" u-hot="{$goods.hot}" u-uid="{$goods.id}">NO</a></td>
                                {/if}


                                {if $goods.status==1}
                                <td class="am-hide-sm-only"><a class="u-status" u-status="{$goods.status}" u-uid="{$goods.id}">激活</a></td>
                                {else}
                                <td class="am-hide-sm-only"><a style="color: #93a2a9" class="u-status" u-status="{$goods.status}" u-uid="{$goods.id}">禁用</a></td>
                                {/if}



                                <td>
                                    <div class="">
                                        <div class="am-btn-group am-btn-group-xs">

                                            <a href="{:url('goods/Goods/edit',['id'=>$goods.id])}" class="am-btn am-btn-default am-btn-xs am-hide-sm-only fff"><span class="am-icon-copy"></span> 编辑</a>
                                            <button type="button" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only btn-del" iddata="{$goods.id}"><span class="am-icon-trash-o"></span> 删除商品</button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        <div class="am-cf">
                            <div class="am-fr">
                                {$data->render()}
                            </div>
                        </div>
                        <hr>

                    </form>
                </div>

            </div>
        </div>
        <div class="tpl-alert"></div>
    </div>
</div>

<script>
    $(function () {
        $('.btn-del').click(function(){
            var id = $(this).attr('iddata');
            var obj = $(this).parents('tr');
//                console.log($(this).attr('iddata'))
            if(confirm('你确定要删除该商品吗')){
                delajax(id,obj,'goods');
                $('.goodscount').html($('.goodscount').html()-1);
            }
        });

        // 禁用/激活商品
        var $ustu = $('.u-status');
        $ustu.click(function(){
            var uid = $(this).attr('u-uid');
            var stu = $(this).attr('u-status');
            var obj = $(this);
//           console.log(stu);
            csajax(uid,stu,obj,'/goods/goods/changestatus');
        });

        // 商品hot/nohot
        var $uhot = $('.u-hot');
        $uhot.click(function(){
            var uid = $(this).attr('u-uid');
            var stu = $(this).attr('u-hot');
            var obj = $(this);
//           console.log(stu);
            chajax(uid,stu,obj,'/goods/goods/changehot');
        });

        $('.am-icon-search').click(function () {
            var code = $('#findcode').val();
//            alert('admin/User/'+tel);
            window.location.href = '/goods/'+code;
        })
    })
</script>
{/block}